#ifndef __HTTP_REQUEST_H__
#define __HTTP_REQUEST_H__

#include <string>
#include <unordered_map>
#include <unordered_set>
#include <string_view>
#include <regex>
#include <glog/logging.h>
#include "../buffer/buffer.h"

class HttpRequest
{
public:
    enum class ParseState
    {
        PARSE_LINE = 0,
        PARSE_HEAD,
        PARSE_BODY,
        FINISH
    };

    // enum class HttpCode
    // {
    //     NO_REQUEST = 0,
    //     GET_REQUEST,
    //     BAD_REQUEST,
    //     NO_RESOURSE,
    //     FORBIDDENT_REQUEST,
    //     FILE_REQUEST,
    //     INTERNAL_ERROR,
    //     CLOSED_CONNECTION
    // };

    HttpRequest();
    ~HttpRequest() = default;
    void Init();
    bool Parse(Buffer &buffer);

    std::string GetMethod();
    std::string GetPath() const;
    std::string &GetPath();
    std::string GetVersion() const;
    std::string GetPost(const std::string &key) const;
    std::string GetPost(const char* key) const;

    bool IsKeepAlive() const;

private:
    bool ParseRequestLine(const std::string& line);
    void ParseHeader(const std::string& line);
    void ParseBody(const std::string& line);

    void ParsePath();
    void ParsePost();


private:

    std::string method_;
    std::string path_;
    std::string version_;
    std::string body_;
    ParseState state_;

    std::unordered_map<std::string, std::string> header_;
    std::unordered_map<std::string, std::string> post_;
};

#endif /* __HTTP_REQUEST_H__ */
